package STUDENT.TranMinhVu.OOPS.ArrayExercises.BaiTapQuanLySachThuVien;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Views {
	public static void Menu(){
		System.out.println("Chuong trinh quan ly sach");
		System.out.println("-----------------------------------------");
		System.out.println("1 - Nhap du lieu sach");
		System.out.println("2 - Nhap du lieu ban doc");
		System.out.println("3 - In danh sach sach");
		System.out.println("4 - In danh sach ban doc");
		System.out.println("5 - Nhap du lieu muon sach");
		System.out.println("6 - In danh sach ban doc muon sach");
		System.out.println("7 - Sap xep danh sach theo ten ban doc");
		System.out.println("8 - Sap xep danh sach theo so sach muon");
		System.out.println("9 - Tim kiem va hien thi thong tin muon sach");
	}
	
	public static void main(String[] args) {
		List<Sach> booklist = new ArrayList<Sach>();
		List<BanDoc> readerlist = new ArrayList<BanDoc>();
		List<BangQLMuonSach> dsbql = new ArrayList<BangQLMuonSach>();
		int w = 0;
		while(w==0){
		Menu();
		Scanner sc = new Scanner(System.in);
		Controllers objcontrollers = new Controllers();
		int x = sc.nextInt();
		sc.nextLine();
		switch (x){
			case 1: objcontrollers.BookInput(booklist);
				break;
			case 2: objcontrollers.ReaderInput(readerlist);
				break;
			case 3: objcontrollers.BookOutput(booklist);
				break;
			case 4: objcontrollers.ReaderOutput(readerlist);
				break;
			case 5: 
				System.out.println("Nhap so ban muon sach");
				int sobanmuonsach = sc.nextInt();
				sc.nextLine();
				for (int j=0;j<sobanmuonsach;j++){
					BangQLMuonSach bql = new BangQLMuonSach();
					int j1 = j+1;
					System.out.println("Nhap du lieu ban doc thu "+j1+":");
					System.out.println("Nhap ten ban doc");
					bql.setTenbandoc(sc.nextLine());
					System.out.println("Nhap ma ban doc");
					bql.setMabandoc(sc.nextInt());
					sc.nextLine();
					System.out.println("Nhap so dau sach");
					bql.setSodausach(sc.nextInt());
					sc.nextLine();
					int[] masachmuon = new int[bql.getSodausach()];
					String[] tensachmuon = new String[bql.getSodausach()];
					int[] sosachmuon = new int[bql.getSodausach()]; //So sach muon moi loai
					for (int t = 0; t<bql.getSodausach();t++){
						int t1 = t+1;
						System.out.println("Nhap du lieu dau sach thu "+t1+":");
						System.out.println("Nhap ma dau sach");
						masachmuon[t]=sc.nextInt();
						sc.nextLine();
						System.out.println("Nhap ten sach");
						tensachmuon[t]=sc.nextLine();
						System.out.println("Nhap so sach muon");
						sosachmuon[t]=sc.nextInt();
						sc.nextLine();
					}
					bql.setMasachmuon(masachmuon);
					bql.setDausach(tensachmuon);
					bql.setSosachmuon(sosachmuon);
					if(objcontrollers.Kiemtrathongtin(bql, booklist, readerlist))
					{dsbql.add(bql);}
				}
				break;
			case 6: 
		        System.out.println("Thong tinh bang quan li: ");
				System.out.println("***********************************");
				for (BangQLMuonSach bql : dsbql) {
					System.out.println(bql);
				}
				break;
			case 7: 
				Collections.sort(dsbql, new NameComparator());
				for (BangQLMuonSach bql : dsbql) {
					System.out.println(bql);
				}
				break;
			case 8:
				Collections.sort(dsbql, new NumOfBookComparator());
				for (BangQLMuonSach bql : dsbql) {
					System.out.println(bql);					
				}
				break;
			case 9:
				System.out.println(objcontrollers.FindReader(dsbql));
				break;
				
		}	
		System.out.println("Nhap -1 de dung chuong trinh\nNhap 0 de quay lại menu");
		if(sc.nextInt()==-1)break;
	}
	}	
}
